package com.jp.vn.main;

import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.Html;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jp.vn.CustomAdapter.ViewPagerAdapter;

public class MenuActivity extends BaseActivity {

	ViewPager menu_view;
	private LinearLayout dotsLayout;
	private TextView[] dots;
	ViewPagerAdapter adapter;
	RelativeLayout layout;
	public static int width;
	public static int height;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_menu);

		menu_view = (ViewPager) findViewById(R.id.menu_view);
		dotsLayout = (LinearLayout) findViewById(R.id.viewPagerCountDots);
		
		adapter = new ViewPagerAdapter(this);
		menu_view.setAdapter(adapter);
		menu_view.setCurrentItem(0);
		setPageIndicator();
		menu_view.setOnPageChangeListener(new OnPageChangeListener() {

			@Override
			public void onPageSelected(int position) {
				for (int i = 0; i < 2; i++) {
					dots[i].setTextColor(Color.parseColor("#f996b4"));
				}
				dots[position].setTextColor(Color.parseColor("#f75f86"));
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {

			}

			@Override
			public void onPageScrollStateChanged(int arg0) {

			}
		});

	}

	public void setPageIndicator() {
		dots = new TextView[2];

		for (int i = 0; i < 2; i++) {
			dots[i] = new TextView(this);
			dots[i].setText(Html.fromHtml("&#8226;"));
			
			Configuration config = getResources().getConfiguration();
			
			if ((config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL){
				dots[i].setTextSize(30);
			}
			
			if ((config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL){
				dots[i].setTextSize(30);
			}
			
			if ((config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE){
				dots[i].setTextSize(60);
			}
			
			dots[i].setTextColor(Color.parseColor("#f996b4"));
			dotsLayout.addView(dots[i]);
		}

		dots[0].setTextColor(Color.parseColor("#f75f86"));
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		finish();
	}
	
	@Override
	public void onBackPressed() {
		super.onBackPressed();
		overridePendingTransition(R.anim.left_in, R.anim.right_out);
		finish();
	}

}
